﻿using BackData;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC.API.Command.Role;
using RBAC.API.Command.User;
using RBAC.API.DTOs;

namespace RBAC.API.Controllers
{
    /// <summary>
    /// 角色控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class RolesController : ControllerBase
    {
        IMediator mediator;

        public RolesController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 获取角色列表
        /// </summary>
        /// <param name="request">参数</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>角色列表</returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
       // [AllowAnonymous]
        public Task<ApiPaging<RoleDTO>> RoleGet([FromQuery]RoleGetCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="request">主键</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>影响行数</returns>
        [HttpPut]

        public async Task<ApiResult<int>> RoleDel(RoleDelCommand request)
        {
            return await mediator.Send(request);
        }
         
        ////////////////////////////////////////////////////////////今晚测试角色添加
        /// <summary>
        /// 角色添加
        /// </summary>
        /// <param name="request">参数</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>影响行数</returns>
        [HttpPost]
        public async Task<ApiResult<int>> RoleAdd(RoleAddCommand request) 
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 修改角色信息
        /// </summary>
        /// <param name="request">参数</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>影响行数</returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<ApiResult<int>> RoleUpdate(RoleUpdateCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
